<?php

include dirname(dirname(dirname(__FILE__))) . '/include/common.php';

class webServiceDeleteBudgetItem extends core {

    public function process() {
        $item_id = intval($_POST['item_id']);
        $user_id = intval($_POST['user_id']);
        $data = $this->db->get_row("SELECT * FROM budget_items WHERE `item_id`='$item_id' AND `user_id`='$user_id'");
        if ($data) {         
            $query = "DELETE FROM budget_items WHERE `item_id`= '$item_id' AND `user_id`='$user_id'";

            if ($this->db->query($query)===false) {

                $this->_JSONResponse(array('error' => 1, 'msg' => 'Oops, something went wrong. Please try again'));
            } else {
                $this->_JSONResponse(array('error' => 0, 'msg' => 'Item has been removed'));
            }
        } else {
            $this->_JSONResponse(array('error' => 1, 'msg' => 'Item does not exist'));
        }
    }

}

$processor = new webServiceDeleteBudgetItem();
$processor->process();
?>